import { BasicColumn, FormSchema } from '@apps/antd-admin/src/components/Table';
import { serverList } from '@apps/ant-bus/src/views/business/goods/server/api';
import { categoryList } from '@apps/ant-bus/src/views/business/goods/category/api';
import { goodsList } from '@apps/ant-bus/src/views/business/goods/goods/api';
import { employeeList } from '@apps/ant-bus/src/views/business/employeeManage/employee/data/api';

export const columns: BasicColumn[] = [
  {
    title: '员工',
    dataIndex: 'employeeName',
    width: 140,
  },
  {
    title: '服务类型',
    dataIndex: 'serverType',
    width: 140,
    customRender: ({ record }: Recordable) => {
      const serverTypes = [
        { label: '服务列表', value: '1' },
        { label: '单次产品', value: '2' },
      ];
      const serverType: any = serverTypes.find((item) => item.value == record.serverType);
      if (serverType) {
        return serverType.label;
      }
      return '';
    },
  },
  {
    title: '服务名称',
    dataIndex: 'serverName',
    width: 160,
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 150,
  },
];

export const searchFormSchema: FormSchema[] = [];

export const formSchema: FormSchema[] = [
  {
    label: '员工',
    field: 'employeeId',
    component: 'ApiSelect',
    required: true,
    dynamicDisabled: true,
    componentProps: {
      api: employeeList,
      params: { handlerName: 'busEmployeeListHandler' },
      labelField: 'employeeName',
      valueField: 'employeeId',
      immediate: true,
      showSearch: true,
    },
  },
  {
    label: '服务类型',
    field: 'serverType',
    component: 'Select',
    required: true,
    componentProps: ({ formModel }) => {
      return {
        options: [
          { label: '服务列表', value: 1 },
          { label: '单次产品', value: 2 },
        ],
        onChange(serverType) {
          formModel.serverId = null;
        },
      };
    },
  },
  {
    label: '服务名称',
    field: 'serverId',
    component: 'ApiSelect',
    required: false,
    componentProps: {
      api: serverList,
      labelField: 'serverName',
      valueField: 'serverId',
      immediate: true,
      showSearch: true,
    },
    ifShow: ({ model }) => {
      return model.serverType == 1;
    },
  },
  {
    label: '商品分类',
    field: 'categoryId',
    component: 'ApiSelect',
    required: false,
    componentProps: ({ formModel }) => {
      return {
        api: categoryList,
        params: { categoryCodes: 'viproom,viponly' },
        labelField: 'categoryName',
        valueField: 'categoryId',
        immediate: true,
        showSearch: true,
        onChange(categoryId) {
          formModel.serverId = null;
        },
      };
    },
    ifShow: ({ model }) => {
      return model.serverType == 2;
    },
  },
  {
    label: '单次商品',
    field: 'serverId',
    component: 'ApiSelect',
    required: false,
    componentProps: ({ formActionType, formModel }) => {
      let categoryId = formModel.categoryId;
      return {
        api: goodsList,
        params: { categoryId: categoryId },
        labelField: 'goodsName',
        valueField: 'goodsId',
        immediate: true,
        showSearch: true,
      };
    },
    ifShow: ({ model }) => {
      return model.serverType == 2;
    },
  },
];
